package com.zzti.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zzti.dao.UserDao;
import com.zzti.util.DButil;

@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		// 获取登录账户信息
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		// 连接数据库进行数据查询
		UserDao userDao = new UserDao();
		boolean flag = userDao.queryUser(username, password);
		if (flag) {
			response.sendRedirect(request.getContextPath() + "/FindEmployee");
		} else {
			String error = "登录失败，账号或密码错误，请重新输入";
			request.setAttribute("error", error);
			request.getRequestDispatcher("login.jsp").forward(request, response);
		}
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
